<template>
    	<div class="wrapper">
		<div class="header">好友验证</div>
		<div class="content">
			<div class="friend_img">
				<img src="img/face_1.png" id="userImg">
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">账号</span>
						<span class="items_text">{{addInfo.userId}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">昵称</span>
						<span class="items_text">{{addInfo.userNick}}</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
			</div>
			<div class="user_info2">
				<div class="user_underline">
					<div class="items_left">
						<span class="items_title">好友验证问题</span>
						<span class="items_text">请问你为什么要加我？</span>
					</div>
					<!-- <div class="items_right"><i class="iconfont icon-dayuhao"></i></div> -->
				</div>
				<div class="text_area" id="words">
					<textarea></textarea>
				</div>
			</div>
			<div class="check_btns">
				<button class="add_back">加入黑名单</button>
				<button class="add_friend" @click="applyAddFriend()">通过验证</button>
			</div>
		</div>
	</div>
</template>

<script>
import $ from 'jquery'
import Client from '../../config/common'
export default {
    data(){
        return{
			loginInfo:{},
			addInfo:{}
        }
    },
    created(){
		Client.login(loginInfo => {
			this.loginInfo = loginInfo;
		});
		this.addInfo.userImg = Client.getQueryString('img');
		let newNick = Client.getQueryString('nick');
		this.addInfo.userNick = decodeURI(newNick);
		this.addInfo.userId = Client.getQueryString('id');
	},
	mounted(){
		
    },

    components:{
       // headTop
    },

    computed:{

    },

    methods:{
		applyAddFriend(){

			var len = $("#words").val();
			if (len > 120) {
				alert('您输入的留言超过字数限制(最长40个汉字)');
				return;
			}
			var add_friend_item = [
				{
					'To_Account': this.addInfo.userId,
					"AddSource": "AddSource_Type_Unknow",
					"AddWording": $("#words").val() //加好友附言，可为空
				}
			];
			var options = {
				'From_Account': this.loginInfo.identifier,
				'AddFriendItem': add_friend_item
			};

			webim.applyAddFriend(
				options,
				(resp) => {
					console.log(resp);
					if (resp.Fail_Account && resp.Fail_Account.length > 0) {
						for (var i in resp.ResultItem) {
							alert(resp.ResultItem[i].ResultInfo);
							break;
						}
					} else {

						alert('申请添加好友成功');

					}
				},
				function (err) {
					alert(err.ErrorInfo);
				}
			);
		}
    },
}

</script>

<style lang="scss"> 
   @import '../../style/friend_check';
</style>